package com.dmzapp.cashoffer;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;

import com.huluwa.dmzapp.cashoffer.R;

public class FirstStartActivity extends SuperActivity implements OnGestureListener {

    private GestureDetector detector;

    private ViewFlipper flipper;

    private final int HELPFILP_RESULT = 106;

    Intent getMainActivity = null;

    int count = 1;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
//        drawBackground();
        LayoutInflater inflater = LayoutInflater.from(this);
        final View layout = inflater.inflate(R.layout.view_flipper, null);
        setContentView(layout);
        flipper = (ViewFlipper) findViewById(R.id.view_flipper);
        detector = new GestureDetector(this);

    }

    public void drawBackground() {

        GradientDrawable grad = new GradientDrawable(Orientation.TL_BR, new int[] { Color.rgb(0, 0, 127), Color.rgb(0, 0, 255), Color.rgb(127, 0, 255),
                Color.rgb(127, 127, 255), Color.rgb(127, 255, 255), Color.rgb(255, 255, 255) });
        this.getWindow().setBackgroundDrawable(grad);

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return this.detector.onTouchEvent(event);
    }

    public boolean onDown(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;

    }

    public boolean onFling(MotionEvent e1, MotionEvent e2, float arg2, float arg3) {
        Log.i("Fling", "Fling Happened!");
        if (e1.getX() - e2.getX() > 5) {
            this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
            this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
            if (count < 3) {
                this.flipper.showNext();
                count++;
            } else if (count == 3) {
                Intent intent = new Intent();
                finish();
                intent.setClass(this, LoginActivity.class);
                startActivity(intent);
            }
            return true;

        } else if (e1.getX() - e2.getX() < -5) {
            this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in));
            this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out));
            if (count > 1) {
                this.flipper.showPrevious();
                count--;
            }
            return true;
        }

        return true;

    }

    public void onLongPress(MotionEvent arg0) {

        // TODO Auto-generated method stub

    }

    public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,

    float arg3) {

        // TODO Auto-generated method stub

        return false;

    }

    public void onShowPress(MotionEvent arg0) {

        // TODO Auto-generated method stub

    }

    public boolean onSingleTapUp(MotionEvent arg0) {

        // TODO Auto-generated method stub

        return false;

    }

}